package RJZ.Rainbow.Controller;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

@Component
public class Welcompanel extends JPanel implements InitializingBean {
    @Autowired
    UIConruoller uiConruoller;
    JLabel label = new JLabel("1.先请选择操作");
    JButton Take = new JButton("我要取件");
    JButton Sub = new JButton("我要投件");


    @Autowired
    SubPanel subPanel;
    @Autowired
    TakePanel takePanel;

    public Welcompanel() {
        setSubListener();
        setTakeListener();
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        setSize(d.width, d.height/2);
    }

    public void setTakeListener() {
        Take.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                ((CardLayout) uiConruoller.getLow().getLayout()).show(uiConruoller.getLow(), "take");
                takePanel.focus();
            }

            @Override
            public void mousePressed(MouseEvent e) {

            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });
    }

    public void setSubListener() {
        Sub.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                ((CardLayout) uiConruoller.getLow().getLayout()).show(uiConruoller.getLow(), "sub");
                subPanel.focus();
            }

            @Override
            public void mousePressed(MouseEvent e) {

            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        this.add(label, BorderLayout.CENTER);
        this.add(Take, BorderLayout.CENTER);
        this.add(Sub, BorderLayout.CENTER);
        setVisible(true);
    }
}
